using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CreateBall : MonoBehaviour
{
    public GameObject ball, ballList;
    public Transform cupTrans;
    public TextMesh ballNumText;
    public int startNum;
    int i;

    void Start()
    {
        startNum = int.Parse(ballNumText.text);
        i = startNum;
        
        StartCoroutine(Create());
    }

    IEnumerator Create()
    {
        while (i > 0)
        {
            yield return new WaitForSeconds(0.5f);
            GameObject item = GameObject.Instantiate(ball, cupTrans.position, cupTrans.rotation);
            item.transform.SetParent(ballList.transform);
            
            i--;
            startNum--;
            
            ballNumText.text = startNum.ToString();
            
        }
    }

}
